package main.java.org.mapper;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import main.java.Exam.pojo.Entity.Questtion;
import main.java.Exam.pojo.Entity.TestQuestion;
import main.java.Exam.pojo.tableDTO.QuesttionDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    //添加题目
    @Insert("INSERT INTO tb_questions ( questionId,type, score, content, answer,options ) VALUES (#{questionId},#{type}, #{score}, #{content}, #{answer}, #{options, typeHandler=main.java.org.result.ListTypeHandler})")
    void insert(QuesttionDTO questtionDTO);
    //删除题目
    @Delete("DELETE FROM tb_questions WHERE questionId = #{questionId} AND type=#{type}")
    void delete(Integer questionId, Integer type);

    //分页查询
    @Select("SELECT questionId, type,  score,  content, answer, options,create_time,update_time FROM tb_questions WHERE 1=1")
    Page<Questtion> selectPage(Page<Questtion> page);
    //修改题目
    @Update("UPDATE tb_questions SET type = #{type},score = #{score},content = #{content},answer = #{answer},  options = #{options, typeHandler=main.java.org.result.ListTypeHandler} WHERE questionId = #{questionId}")
    void updata(QuesttionDTO questionDTO);
    //显示题目
    @Select("SELECT * FROM tb_questions WHERE type = #{type} AND questionid IN (#{ids})")
    List<Questtion> selectByTypeAndIds(@Param("list") List<TestQuestion> testQuestions);
//查询单个题目
    @Select("select questionId, type,  score,  content, answer, options,create_time,update_time FROM tb_questions WHERE questionid=#{questionId} and type=#{type}")
    Questtion  getquestion(Integer questionId, Integer type);
@Select("select * from tb_questions where questionid=#{questionId}")
    Questtion getQuestionById(Integer questionId);
}
